package com.zyf.workflow.test.work;

import com.zyf.workflow.business.fwupgrade.FwUpgradeBean;
import com.zyf.workflow.business.fwupgrade.PackageWorker;
import com.zyf.workflow.node.Node;
import com.zyf.workflow.node.WorkNode;
import com.zyf.workflow.node.bean.NodeType;
import com.zyf.workflow.work.AbstractWork;
import com.zyf.workflow.work.bean.WorkTypeEnum;
import com.zyf.workflow.worker.Worker;

import java.util.ArrayList;
import java.util.List;

public class CheckInOrOutBandWork<T> extends AbstractWork<List<FwUpgradeBean>> {

    public CheckInOrOutBandWork(List<FwUpgradeBean> data, String workName) {

        super(data, workName);
    }

    private Node<String> getCheckNode(List<FwUpgradeBean> fwUpgradeBeans) {
        PackageWorker packageWorker = new PackageWorker();
        Worker<List<FwUpgradeBean>, String, String> worker = packageWorker::checkInOrOutBand;
        return new WorkNode.Builder<List<FwUpgradeBean>, String>()
                .withWorker(worker)
                .withNodeId(5)
                .withData(fwUpgradeBeans)
                .withName("check")
                .setCallBack((data,param) -> {
                    System.out.println("check band type finished");
                    System.out.println(".....");
                })
                .withType(NodeType.DECISION)
                .create();
    }

    @Override
    public List<Node<?>> initNodes(List<FwUpgradeBean> data) {
        List<FwUpgradeBean> fwUpgradeBeanList = (List<FwUpgradeBean>) data;
        Node<String> checkNode = getCheckNode(fwUpgradeBeanList);
        List<Node<?>> nodes = new ArrayList<>();
        nodes.add(checkNode);
        return nodes;

    }

    @Override
    public WorkTypeEnum getWorkType() {
        return WorkTypeEnum.DECISION;
    }
}
